/* eslint-disable @typescript-eslint/no-explicit-any */
/*
 *  Copyright 2021 Collate
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

 /**
 * Create Metadata Service entity request
 */
export interface CreateMetadataService {
    connection?: MetadataConnection;
    /**
     * Description of Metadata entity.
     */
    description?: string;
    /**
     * Display Name that identifies this Metadata service.
     */
    displayName?: string;
    /**
     * Name that identifies the this entity instance uniquely
     */
    name: string;
    /**
     * Owner of this Metadata service.
     */
    owner?:      EntityReference;
    serviceType: MetadataServiceType;
    /**
     * Tags for this Metadata Service.
     */
    tags?: TagLabel[];
}

/**
 * Metadata Service Connection.
 */
export interface MetadataConnection {
    config?: Connection;
}

/**
 * Amundsen Connection Config
 *
 * Metadata to ElasticSearch Connection Config
 *
 * OpenMetadata Connection Config
 *
 * Atlas Connection Config
 *
 * Alation Connection Config
 */
export interface Connection {
    /**
     * Enable encryption for the Amundsen Neo4j Connection.
     */
    encrypted?: boolean;
    /**
     * Host and port of the Amundsen Neo4j Connection. This expect a URI format like:
     * bolt://localhost:7687.
     *
     * OpenMetadata Server Config. Must include API end point ex: http://localhost:8585/api
     *
     * Host and port of the Atlas service.
     *
     * Host and port of the Alation service.
     */
    hostPort?: string;
    /**
     * Maximum connection lifetime for the Amundsen Neo4j Connection.
     */
    maxConnectionLifeTime?: number;
    /**
     * password to connect to the Amundsen Neo4j Connection.
     *
     * password to connect  to the Atlas.
     */
    password?:                   string;
    supportsMetadataExtraction?: boolean;
    /**
     * Service Type
     */
    type?: MetadataServiceType;
    /**
     * username to connect to the Amundsen Neo4j Connection.
     *
     * username to connect  to the Atlas. This user should have privileges to read all the
     * metadata in Atlas.
     */
    username?: string;
    /**
     * Enable SSL validation for the Amundsen Neo4j Connection.
     */
    validateSSL?: boolean;
    /**
     * Maximum number of events sent in a batch (Default 100).
     */
    batchSize?: number;
    /**
     * List of entities that you need to reindex
     */
    entities?:      string[];
    recreateIndex?: boolean;
    runMode?:       RunMode;
    /**
     * Recreate Indexes with updated Language
     */
    searchIndexMappingLanguage?: SearchIndexMappingLanguage;
    /**
     * OpenMetadata server API version to use.
     */
    apiVersion?:   string;
    authProvider?: AuthProvider;
    /**
     * Cluster name to differentiate OpenMetadata Server instance
     */
    clusterName?: string;
    /**
     * Configuration for Sink Component in the OpenMetadata Ingestion Framework.
     */
    elasticsSearch?: ElasticsSearch;
    /**
     * Validate Openmetadata Server & Client Version.
     */
    enableVersionValidation?: boolean;
    extraHeaders?:            { [key: string]: string };
    /**
     * Force the overwriting of any entity during the ingestion.
     */
    forceEntityOverwriting?: boolean;
    /**
     * Include Dashboards for Indexing
     */
    includeDashboards?: boolean;
    /**
     * Include Database Services for Indexing
     */
    includeDatabaseServices?: boolean;
    /**
     * Include Glossary Terms for Indexing
     */
    includeGlossaryTerms?: boolean;
    /**
     * Include Messaging Services for Indexing
     */
    includeMessagingServices?: boolean;
    /**
     * Include MlModels for Indexing
     */
    includeMlModels?: boolean;
    /**
     * Include Pipelines for Indexing
     */
    includePipelines?: boolean;
    /**
     * Include Pipeline Services for Indexing
     */
    includePipelineServices?: boolean;
    /**
     * Include Tags for Policy
     */
    includePolicy?: boolean;
    /**
     * Include Tables for Indexing
     */
    includeTables?: boolean;
    /**
     * Include Tags for Indexing
     */
    includeTags?: boolean;
    /**
     * Include Teams for Indexing
     */
    includeTeams?: boolean;
    /**
     * Include Topics for Indexing
     */
    includeTopics?: boolean;
    /**
     * Include Users for Indexing
     */
    includeUsers?: boolean;
    /**
     * Limit the number of records for Indexing.
     */
    limitRecords?:           number;
    secretsManagerLoader?:   SecretsManagerClientLoader;
    secretsManagerProvider?: SecretsManagerProvider;
    /**
     * OpenMetadata Client security configuration.
     */
    securityConfig?: OpenMetadataJWTClientConfig;
    sslConfig?:      Config;
    /**
     * If set to true, when creating a service during the ingestion we will store its Service
     * Connection. Otherwise, the ingestion will create a bare service without connection
     * details.
     */
    storeServiceConnection?:                    boolean;
    supportsDataInsightExtraction?:             boolean;
    supportsElasticSearchReindexingExtraction?: boolean;
    verifySSL?:                                 VerifySSL;
    connectionArguments?:                       { [key: string]: any };
    connectionOptions?:                         { [key: string]: string };
    /**
     * service type of the data source.
     */
    databaseServiceName?: string[];
    /**
     * Name of the Entity Type available in Atlas.
     */
    entity_type?: string;
    /**
     * service type of the messaging source
     */
    messagingServiceName?: string[];
    /**
     * Custom OpenMetadata Classification name for alation tags.
     */
    alationTagClassificationName?: string;
    /**
     * Types of methods used to authenticate to the alation instance
     */
    authType?: AuthenticationTypeForAlation;
    /**
     * Choose between mysql and postgres connection for alation database
     */
    connection?: AlationDatabaseConnection;
    /**
     * Specifies if hidden datasources should be included while ingesting.
     */
    includeHiddenDatasources?: boolean;
    /**
     * Specifies if undeployed datasources should be included while ingesting.
     */
    includeUndeployedDatasources?: boolean;
    /**
     * Specifies if Dashboards are to be ingested while running the ingestion job.
     */
    ingestDashboards?: boolean;
    /**
     * Specifies if Datasources are to be ingested while running the ingestion job.
     */
    ingestDatasources?: boolean;
    /**
     * Specifies if Domains are to be ingested while running the ingestion job.
     */
    ingestDomains?: boolean;
    /**
     * Specifies if Knowledge Articles are to be ingested while running the ingestion job.
     */
    ingestKnowledgeArticles?: boolean;
    /**
     * Specifies if Users and Groups are to be ingested while running the ingestion job.
     */
    ingestUsersAndGroups?: boolean;
    /**
     * Pagination limit used for Alation APIs pagination
     */
    paginationLimit?: number;
    /**
     * Project name to create the refreshToken. Can be anything
     */
    projectName?: string;
}

/**
 * OpenMetadata Server Authentication Provider. Make sure configure same auth providers as
 * the one configured on OpenMetadata server.
 */
export enum AuthProvider {
    Auth0 = "auth0",
    AwsCognito = "aws-cognito",
    Azure = "azure",
    Basic = "basic",
    CustomOidc = "custom-oidc",
    Google = "google",
    LDAP = "ldap",
    Okta = "okta",
    Openmetadata = "openmetadata",
    Saml = "saml",
}

/**
 * Types of methods used to authenticate to the alation instance
 *
 * 基本身份验证凭据
 *
 * API访问令牌认证凭据
 */
export interface AuthenticationTypeForAlation {
    /**
     * 访问服务的密码
     */
    password?: string;
    /**
     * 访问服务的用户名
     */
    username?: string;
    /**
     * 用于API的访问令牌
     */
    accessToken?: string;
}

/**
 * Choose between mysql and postgres connection for alation database
 *
 * Postgres Database Connection Config
 *
 * Mysql Database Connection Config
 */
export interface AlationDatabaseConnection {
    /**
     * 选择鉴权的配置
     *
     * Choose Auth Config Type.
     */
    authType?: AuthConfigurationType;
    /**
     * Custom OpenMetadata Classification name for Postgres policy tags.
     */
    classificationName?:  string;
    connectionArguments?: { [key: string]: any };
    connectionOptions?:   { [key: string]: string };
    /**
     * 数据源的数据库。此参数是可选的，如果您希望将元数据读取限制在单个数据库中，可以填写此参数。如果留空，OpenMetadata Ingestion 会尝试扫描所有数据库。
     */
    database?: string;
    /**
     * 服务源的host和port
     *
     * Host and port of the MySQL service.
     */
    hostPort?: string;
    /**
     * 从 Postgres 中的所有数据库获取数据。您可以在此基础上使用 databaseFilterPattern。
     */
    ingestAllDatabases?:      boolean;
    sampleDataStorageConfig?: SampleDataStorageConfig;
    /**
     * SQLAlchemy 驱动架构选项
     *
     * SQLAlchemy driver scheme options.
     */
    scheme?: Scheme;
    /**
     * SSL Configuration details.
     */
    sslConfig?:                  Config;
    sslMode?:                    SSLMode;
    supportsDatabase?:           boolean;
    supportsDBTExtraction?:      boolean;
    supportsLineageExtraction?:  boolean;
    supportsMetadataExtraction?: boolean;
    supportsProfiler?:           boolean;
    supportsQueryComment?:       boolean;
    supportsUsageExtraction?:    boolean;
    /**
     * 服务类型
     *
     * Service Type
     */
    type?: Type;
    /**
     * 要连接到 Postgres 的用户名。此用户应具有读取 Postgres 中所有元数据的权限。
     *
     * Username to connect to MySQL. This user should have privileges to read all the metadata
     * in Mysql.
     */
    username?: string;
    /**
     * Optional name to give to the database in OpenMetadata. If left blank, we will use default
     * as the database name.
     */
    databaseName?: string;
    /**
     * Database Schema of the data source. This is optional parameter, if you would like to
     * restrict the metadata reading to a single schema. When left blank, OpenMetadata Ingestion
     * attempts to scan all the schemas.
     */
    databaseSchema?: string;
}

/**
 * 选择鉴权的配置
 *
 * Choose Auth Config Type.
 *
 * Common Database Connection Config
 *
 * IAM Auth Database Connection Config
 *
 * Azure Database Connection Config
 */
export interface AuthConfigurationType {
    /**
     * Password to connect to source.
     */
    password?:    string;
    awsConfig?:   AWSCredentials;
    azureConfig?: AzureCredentials;
}

/**
 * AWS凭据配置
 */
export interface AWSCredentials {
    /**
     * 要假设的角色的Amazon资源名称（ARN），在假设角色的情况下，这是必需的字段
     */
    assumeRoleArn?: string;
    /**
     * 假定角色会话的标识符，在同一角色由不同主体或出于不同原因假定时，使用角色会话名称唯一标识会话，在假设角色的情况下，这是必需的字段
     */
    assumeRoleSessionName?: string;
    /**
     * 要假设的角色的Amazon资源名称（ARN），在假设角色的情况下，这是可选的字段
     */
    assumeRoleSourceIdentity?: string;
    /**
     * AWS访问密钥ID
     */
    awsAccessKeyId?: string;
    /**
     * AAWS区域
     */
    awsRegion: string;
    /**
     * AWS秘密访问密钥
     */
    awsSecretAccessKey?: string;
    /**
     * AWS会话令牌
     */
    awsSessionToken?: string;
    /**
     * AWS的终端点URL
     */
    endPointURL?: string;
    /**
     * 与boto会话一起使用的配置文件的名称
     */
    profileName?: string;
}

/**
 * Azure Datalake凭据
 */
export interface AzureCredentials {
    /**
     * 您的存储账户的账户名称
     */
    accountName?: string;
    /**
     * 您的服务主体应用程序ID（客户端ID）
     */
    clientId?: string;
    /**
     * 您的服务主体密码（客户端密钥）
     */
    clientSecret?: string;
    /**
     * Scopes to get access token, for e.g. api://6dfX33ab-XXXX-49df-XXXX-3459eX817d3e/.default
     */
    scopes?: string;
    /**
     * Azure订阅的租户ID
     */
    tenantId?: string;
    /**
     * Key Vault Name
     */
    vaultName?: string;
}

/**
 * Storage config to store sample data
 */
export interface SampleDataStorageConfig {
    config?: DataStorageConfig;
}

/**
 * Storage config to store sample data
 */
export interface DataStorageConfig {
    /**
     * Bucket Name
     */
    bucketName?: string;
    /**
     * Provide the pattern of the path where the generated sample data file needs to be stored.
     */
    filePathPattern?: string;
    /**
     * When this field enabled a single parquet file will be created to store sample data,
     * otherwise we will create a new file per day
     */
    overwriteData?: boolean;
    /**
     * Prefix of the data source.
     */
    prefix?:        string;
    storageConfig?: AwsCredentials;
    [property: string]: any;
}

/**
 * AWS凭据配置
 */
export interface AwsCredentials {
    /**
     * 要假设的角色的Amazon资源名称（ARN），在假设角色的情况下，这是必需的字段
     */
    assumeRoleArn?: string;
    /**
     * 假定角色会话的标识符，在同一角色由不同主体或出于不同原因假定时，使用角色会话名称唯一标识会话，在假设角色的情况下，这是必需的字段
     */
    assumeRoleSessionName?: string;
    /**
     * 要假设的角色的Amazon资源名称（ARN），在假设角色的情况下，这是可选的字段
     */
    assumeRoleSourceIdentity?: string;
    /**
     * AWS访问密钥ID
     */
    awsAccessKeyId?: string;
    /**
     * AAWS区域
     */
    awsRegion?: string;
    /**
     * AWS秘密访问密钥
     */
    awsSecretAccessKey?: string;
    /**
     * AWS会话令牌
     */
    awsSessionToken?: string;
    /**
     * AWS的终端点URL
     */
    endPointURL?: string;
    /**
     * 与boto会话一起使用的配置文件的名称
     */
    profileName?: string;
}

/**
 * SQLAlchemy 驱动架构选项
 *
 * SQLAlchemy driver scheme options.
 */
export enum Scheme {
    MysqlPymysql = "mysql+pymysql",
    PgspiderPsycopg2 = "pgspider+psycopg2",
    PostgresqlPsycopg2 = "postgresql+psycopg2",
}

/**
 * 客户端SSL配置
 *
 * SSL Configuration details.
 *
 * OpenMetadata客户端配置以验证SSL证书
 */
export interface Config {
    /**
     * CA证书路径，例如，/path/to/public.cert。如果Verify SSL设置为`validate`，将使用该路径。
     */
    caCertificate?: string;
    /**
     * The SSL certificate used for client authentication.
     */
    sslCertificate?: string;
    /**
     * The private key associated with the SSL certificate.
     */
    sslKey?: string;
}

/**
 * SSL Mode to connect to database.
 */
export enum SSLMode {
    Allow = "allow",
    Disable = "disable",
    Prefer = "prefer",
    Require = "require",
    VerifyCA = "verify-ca",
    VerifyFull = "verify-full",
}

/**
 * 服务类型
 *
 * Service Type
 *
 * Service type.
 */
export enum Type {
    Mysql = "Mysql",
    Postgres = "Postgres",
}

/**
 * Configuration for Sink Component in the OpenMetadata Ingestion Framework.
 */
export interface ElasticsSearch {
    config?: { [key: string]: any };
    /**
     * Type of sink component ex: metadata
     */
    type: string;
}

/**
 * 此模式定义发布器运行模式
 */
export enum RunMode {
    Batch = "batch",
    Stream = "stream",
}

/**
 * Recreate Indexes with updated Language
 *
 * This schema defines the language options available for search index mappings.
 */
export enum SearchIndexMappingLanguage {
    En = "EN",
    Jp = "JP",
    Zh = "ZH",
}

/**
 * 平台 Secrets Manager客户端加载器，通知客户端如何从环境中加载机密管理器凭据
 */
export enum SecretsManagerClientLoader {
    Airflow = "airflow",
    Env = "env",
    Noop = "noop",
}

/**
 * 平台安全管理提供者. 确保配置的安全管理提供者与在平台服务器上配置的相同
 */
export enum SecretsManagerProvider {
    Aws = "aws",
    AwsSsm = "aws-ssm",
    AzureKv = "azure-kv",
    DB = "db",
    InMemory = "in-memory",
    ManagedAws = "managed-aws",
    ManagedAwsSsm = "managed-aws-ssm",
    ManagedAzureKv = "managed-azure-kv",
}

/**
 * OpenMetadata Client security configuration.
 *
 * openMetadataJWTClientConfig安全配置
 */
export interface OpenMetadataJWTClientConfig {
    /**
     * 平台生成的JWT令牌
     */
    jwtToken: string;
}

/**
 * Service Type
 *
 * Amundsen service type
 *
 * Metadata to Elastic Search type
 *
 * OpenMetadata service type
 *
 * Service type.
 *
 * Type of database service such as Amundsen, Atlas...
 */
export enum MetadataServiceType {
    Alation = "Alation",
    Amundsen = "Amundsen",
    Atlas = "Atlas",
    MetadataES = "MetadataES",
    OpenMetadata = "OpenMetadata",
}

/**
 * 客户端SSL验证，确保在启用时配置SSLConfig
 */
export enum VerifySSL {
    Ignore = "ignore",
    NoSSL = "no-ssl",
    Validate = "validate",
}

/**
 * Owner of this Metadata service.
 *
 * This schema defines the EntityReference type used for referencing an entity.
 * EntityReference is used for capturing relationships from one entity to another. For
 * example, a table has an attribute called database of type EntityReference that captures
 * the relationship of a table `belongs to a` database.
 */
export interface EntityReference {
    /**
     * If true the entity referred to has been soft-deleted.
     */
    deleted?: boolean;
    /**
     * Optional description of entity.
     */
    description?: string;
    /**
     * Display Name that identifies this entity.
     */
    displayName?: string;
    /**
     * Fully qualified name of the entity instance. For entities such as tables, databases
     * fullyQualifiedName is returned in this field. For entities that don't have name hierarchy
     * such as `user` and `team` this will be same as the `name` field.
     */
    fullyQualifiedName?: string;
    /**
     * Link to the entity resource.
     */
    href?: string;
    /**
     * Unique identifier that identifies an entity instance.
     */
    id: string;
    /**
     * If true the relationship indicated by this entity reference is inherited from the parent
     * entity.
     */
    inherited?: boolean;
    /**
     * Name of the entity instance.
     */
    name?: string;
    /**
     * Entity type/class name - Examples: `database`, `table`, `metrics`, `databaseService`,
     * `dashboardService`...
     */
    type: string;
}

/**
 * 此模式定义了用于使用标签标记实体的标签类型
 */
export interface TagLabel {
    /**
     * 标签标签的描述
     */
    description?: string;
    /**
     * 标识此标签的显示名称
     */
    displayName?: string;
    /**
     * 到标签资源的链接
     */
    href?: string;
    /**
     *
     * 标签类型描述标签标签是如何应用的，'Manual'表示标签标签是由人员应用的。'Derived'表示使用关联的标签关系导出了标签标签（有关详细信息，请参见Classification.json）。'Propagated`表示标签标签是根据血统从上游传播的。'Automated'在使用工具确定标签标签时使用。
     */
    labelType: LabelType;
    /**
     * 标签或词汇术语的名称
     */
    name?: string;
    /**
     * 标签来自标签还是词汇表
     */
    source: TagSource;
    /**
     * 'Suggested'状态在用户或工具建议标签标签时使用。实体的所有者必须在将其标记为'Confirmed'之前确认建议的标签
     */
    state:  State;
    style?: Style;
    tagFQN: string;
}

/**
 *
 * 标签类型描述标签标签是如何应用的，'Manual'表示标签标签是由人员应用的。'Derived'表示使用关联的标签关系导出了标签标签（有关详细信息，请参见Classification.json）。'Propagated`表示标签标签是根据血统从上游传播的。'Automated'在使用工具确定标签标签时使用。
 */
export enum LabelType {
    Automated = "Automated",
    Derived = "Derived",
    Manual = "Manual",
    Propagated = "Propagated",
}

/**
 * 标签来自标签还是词汇表
 */
export enum TagSource {
    Classification = "Classification",
    Glossary = "Glossary",
}

/**
 * 'Suggested'状态在用户或工具建议标签标签时使用。实体的所有者必须在将其标记为'Confirmed'之前确认建议的标签
 */
export enum State {
    Confirmed = "Confirmed",
    Suggested = "Suggested",
}

/**
 * UI Style is used to associate a color code and/or icon to entity to customize the look of
 * that entity in UI.
 */
export interface Style {
    /**
     * Hex Color Code to mark an entity such as GlossaryTerm, Tag, Domain or Data Product.
     */
    color?: string;
    /**
     * An icon to associate with GlossaryTerm, Tag, Domain or Data Product.
     */
    iconURL?: string;
}
